<template>
	<view>
		<view class="info-1">
			<view class="row1">
				<u-row>
					<u-col span="10"><text>头像:</text></u-col>
					<u-col span="2">
						<u-avatar :src="userinfo.adv"></u-avatar>
					</u-col>
				</u-row>
			</view>
			<view class="">
				<u-row>
					<u-col span="4">
						<text>昵称:</text>
					</u-col>
					<u-col span="8">
						<u--input placeholder="" v-model="userinfo.pickname" border="" inputAlign="right">
							
							
						</u--input>
					</u-col>
				</u-row>
			</view>
			
			<view class="">
				<u-row>
					<u-col span="4">
						<text>账号:</text>
					</u-col>
					<u-col span="8">
						<u--input :disabled="true" placeholder="" v-model="userinfo.username" border="" inputAlign="right">
							
							
						</u--input>
					</u-col>
				</u-row>
			</view>
			
			<view class="">
				<u-row>
					<u-col span="4">
						<text>电话:</text>
					</u-col>
					<u-col span="8">
						<u--input placeholder="" v-model="userinfo.phone" border="" inputAlign="right">
							
						</u--input>
					</u-col>
				</u-row>
			</view>
			
			<view class="">
				<u-row>
					<u-col span="4">
						<text>注册时间:</text>
					</u-col>
					<u-col span="8">
						<u--input placeholder="" v-model="userinfo.updatetime" border="bottom " inputAlign="right"
							:disabled="true">
							
						</u--input>
					</u-col>
				</u-row>
			</view>
			
			<view class="row1">
				<u-row>
					<u-col span="8"><text>性别:</text></u-col>
					<u-col span="4">
						<u-radio-group  v-model="radiovalue" placement="row"  @change="setSex">
							<u-radio 
								:customStyle="{margin: '8rpx'}"
								v-for="(item, index) in radiolist" 
								:key="index"
								:label="item.name" 
								:name="item.name" 
							>
							</u-radio>
						</u-radio-group>
					</u-col>
				</u-row>
			</view>
			<view class="btuuon1">
				<u-button @click="upuserinfo" type="success" size=50 text="保存信息"></u-button>
			</view>
		</view>
		<!-- #ifdef MP-WEIXIN -->
		<view class="">
			<u-divider text="绑定微信" ></u-divider>
				
			<view class="icon_login">
				<u-row justify="center"></u-row>
				<u-icon @click="getWXUserinfo" name="weixin-fill" size="44" color="#2979ff" ></u-icon>
			</view>
			
		</view>
		<!-- #endif -->
		

		<u-notify ref="uNotify"></u-notify>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fileList1: [],
				userinfo: '',
				radiolist: [{
						name: '男',
						disabled: false
					},
					{
						name: '女',
						disabled: false
					},
				],
				radiovalue: '',
				t:''
				
			}
		},
		onLoad() {
			this.userinfo=uni.getStorageSync("userinfo")
			this.radiovalue=this.userinfo.sex
		},
		
		methods: {
			setSex(){
				this.userinfo.sex=this.radiovalue
				
			},
			upuserinfo(){
				this.show = false
					if(this.t){
						clearTimeout(this.t);
					}
					this.t = setTimeout(()=> {
						uni.$u.http.put("users",this.userinfo)
						.then(res => {
							
							this.$refs.uNotify.primary('保存成功')
						})
					}, 1000);
				
				
			},
			getWXUserinfo() {
				let user = uni.getStorageSync('userinfo')

				uni.getUserProfile({
					desc: "获取头像",
					success: (res) => {
						
						let obj = {
							id: user.id,
							adv: res.userInfo.avatarUrl,
							pickname: res.userInfo.nickName
						}

						

						uni.$u.http.put('/users', obj).then(res => {
							console.log(res.data);
							uni.switchTab({
								url: '/pages/user/user'
							})
						})
					}
				})
			},
			// 删除图片
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1)
			},
			// 新增图片
			async afterRead(event) {
				// 当设置 mutiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file)
				let fileListLen = this[`fileList${event.name}`].length
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: 'uploading',
						message: '上传中'
					})
				})
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url)
					let item = this[`fileList${event.name}`][fileListLen]
					this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
						status: 'success',
						message: '',
						url: result
					}))
					fileListLen++
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: 'http://127.0.0.1:2004/upload',
						filePath: url,
						name: 'file',
						formData: {
							user: 'test'
						},
						success: (res) => {
							setTimeout(() => {
								console.log(res.data);
								resolve(res.data.data)
							}, 1000)
						}
					});
				})
			},
		}
	}
</script>

<style scoped>

.info-1 {
		
		margin: 60rpx;
		
	}
	.info text{
		font-size: 30rpx;
		color: #909193;
	}
	.row1{
		/* margin-left: 18rpx; */
	}
	.btuuon1{
		margin-top: 100rpx;
	}
	
</style>
